<?php
	class Model_booking extends CI_Model{
		protected $_table = "tbl_days";
		protected $_ticket  = "tbl_tickets";
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function count_all($day,$month){
			//$query = $this->db->query("select day_id,day_sort,day_info,day_month".$month.",day_tick".$month.",day_num".$month." from ".$this->_table." where day_id < ".($day+1)."");
			$this->db->select("day_id,day_sort,day_info,day_month".$month.",day_tick".$month.",day_num".$month.",tick_val,tick_name");
			$this->db->from($this->_table);
			$this->db->join("tbl_tickets","tbl_tickets.tick_id = tbl_days.day_tick".$month."");
			$this->db->where("day_id <",($day+1));
			return $this->db->count_all_results();
			//return $query->num_rows();
		}
		public function listall($day,$month,$off,$start){
			$this->db->select("day_id,day_sort,day_info,day_month".$month.",day_tick".$month.",day_num".$month.",tick_val,tick_name");
			$this->db->from($this->_table);
			$this->db->join("tbl_tickets","tbl_tickets.tick_id = tbl_days.day_tick".$month."");
			$this->db->where("day_id <",($day+1));
			$this->db->order_by("day_id","ASC");
			$this->db->limit($off,$start);
			return $this->db->get()->result_array();
		}
		public function add($data){
			$this->db->insert($this->_table,$data);
		}
		public function update($data,$day){
			$this->db->where("day_id",$day);
			$this->db->update($this->_table,$data);
		}
		public function getdata($day,$month){
			$query = $this->db->query("select day_id,day_sort,day_info,day_month".$month.",day_tick".$month.",day_num".$month." from ".$this->_table." where day_id = '$day'");
			return $query->row_array();
		}
		public function listtick(){
			$this->db->order_by("tick_id","ASC");
			return $this->db->get($this->_ticket)->result_array();
		}
	}